# coding: utf-8
from PIL import Image


def png_to_ico(png_path, ico_path):
    """
    将PNG图片转换为ICO格式

    Args:
        png_path (str): 原始PNG图片路径
        ico_path (str): 生成ICO图片路径
    """
    try:
        # 打开PNG图片
        with Image.open(png_path) as img:
            # 转换为RGBA模式（支持透明度）
            if img.mode != 'RGBA':
                img = img.convert('RGBA')

            # 保存为ICO格式
            img.save(ico_path, format='ICO')
            print(f"转换成功：{png_path} -> {ico_path}")

    except FileNotFoundError:
        print(f"错误：找不到文件 {png_path}")
    except Exception as e:
        print(f"转换失败：{e}")


if __name__ == "__main__":
    png_path = r"F:\PycharmProjects\download-ui\resource\images\single\Logo.png"
    ico_path = r"F:\PycharmProjects\download-ui\resource\images\single\Logo.ico"
    png_to_ico(png_path, ico_path)
